package com.huawei.fastengine.fastview.startFastappEngine.storage;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;
import java.io.File;
import java.io.IOException;

public class StorageUtils {
    private static final String APP_ENGINE = "fastappEngine";
    private static final String TAG = "StorageUtils";

    public static String getCacheStoragePath(Context context, String str) {
        if (context == null || TextUtils.isEmpty(str)) {
            return null;
        }
        String canonicalPath;
        try {
            canonicalPath = context.getCacheDir().getCanonicalPath();
        } catch (IOException e) {
            FastViewLogUtils.e(TAG, "getCanonicalPath exception");
            canonicalPath = null;
        }
        return canonicalPath != null ? canonicalPath + File.separator + APP_ENGINE + File.separator + str : null;
    }

    public static String getDatabasePath(Context context, String str) {
        String str2 = null;
        if (!(context == null || TextUtils.isEmpty(str))) {
            File databasePath = context.getDatabasePath("app.card." + str + ".db");
            if (databasePath != null && databasePath.exists()) {
                try {
                    str2 = databasePath.getCanonicalPath();
                } catch (IOException e) {
                    FastViewLogUtils.e(TAG, "getCanonicalPath exception");
                }
            }
        }
        return str2;
    }

    public static String getExternalMassPath(Context context, String str) {
        if (!"mounted".equals(Environment.getExternalStorageState()) || context == null || TextUtils.isEmpty(str)) {
            return null;
        }
        String canonicalPath;
        try {
            canonicalPath = context.getExternalFilesDir(APP_ENGINE).getCanonicalPath();
        } catch (Exception e) {
            FastViewLogUtils.e(TAG, "getCanonicalPath exception");
            canonicalPath = null;
        }
        return canonicalPath != null ? canonicalPath + File.separator + str : null;
    }

    public static String getFileStoragePath(Context context, String str) {
        if (context == null || TextUtils.isEmpty(str)) {
            return null;
        }
        String canonicalPath;
        try {
            canonicalPath = context.getFilesDir().getCanonicalPath();
        } catch (IOException e) {
            FastViewLogUtils.e(TAG, "getCanonicalPath exception");
            canonicalPath = null;
        }
        return canonicalPath != null ? canonicalPath + File.separator + APP_ENGINE + File.separator + str : null;
    }
}
